package com.car.rental.common.core.response;

import lombok.Data;

@Data
public class ResponseResult<T> {
    
    // HTTP 状态码常量
    public static final int SUCCESS = 200;  // 成功
    public static final int BAD_REQUEST = 400;  // 请求参数错误
    public static final int UNAUTHORIZED = 401;  // 未授权
    public static final int FORBIDDEN = 403;  // 禁止访问
    public static final int INTERNAL_ERROR = 500;  // 服务器内部错误
    
    private Integer code;  // 状态码
    private String message;  // 提示信息
    private T data;  // 数据
    
    private ResponseResult() {}
    
    public static <T> ResponseResult<T> success() {
        return success(null);
    }
    
    public static <T> ResponseResult<T> success(T data) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(SUCCESS);
        result.setMessage("操作成功");
        result.setData(data);
        return result;
    }
    
    public static <T> ResponseResult<T> error(String message) {
        return error(INTERNAL_ERROR, message);
    }
    
    public static <T> ResponseResult<T> error(Integer code, String message) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public boolean isSuccess() {
        return this.code == 200;
    }
} 